package com.aaa.market.controller;

import com.aaa.common.constant.ReturnCode;
import com.aaa.common.util.Result;
import com.aaa.market.entity.Advertise;
import com.aaa.market.service.AdvertiseService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 广告位(Advertise)表控制层
 *
 * @author makejava
 * @since 2020-11-27 17:24:16
 */
@RestController
@RequestMapping("advertise")
public class AdvertiseController {
    /**
     * 服务对象
     */
    @Resource
    private AdvertiseService advertiseService;

    /**
     * 分页加各种条件查询
     * @param pageNo
     * @param pageSize
     * @param advertise
     * @return
     */
    @RequestMapping("queryPageByParam")
    //@RequestMapping(value = "queryPageByParam",method = RequestMethod.GET)
    public Result queryPageByParam(Integer pageNo, Integer pageSize, Advertise advertise) {
        return advertiseService.queryPageByParam(pageNo,pageSize,advertise);
    }
    /**
     * 通过主键查询单条数据
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Advertise selectOne(Integer id) {
        return this.advertiseService.queryById(id);
    }
    /**
     * 查询所有
     * @param advertise
     * @return
     */
    @GetMapping("selectAll")
    public Result selectAll(Advertise advertise) {
        //返回成功
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),advertiseService.queryAll(advertise));
    }

    /**
     * 添加数据
     * @param advertise
     * @return
     */
    @PostMapping("insert")
    public Result insert(@RequestBody Advertise advertise){
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),advertiseService.insert(advertise));
    }
    /**
     * 修改数据
     * @param advertise
     * @return
     */
    @PostMapping("update")
    public Result update(@RequestBody Advertise advertise){
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),advertiseService.update(advertise));
    }

    /**
     * 删除数据
     * @param id
     * @return
     */
    @RequestMapping("deleteById")
    public Result delete(Integer id){
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),advertiseService.deleteById(id));
    }
}